home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 0758 / setup.arv / DISPATCH.TEM < prev    next >
Encoding:
Text File  |  1997-04-10  |  3.4 KB  |  123 lines

  1. # Dispatcher Error Title 
  2.         $TITLE="Catalog Maker Dispatch Error";
  3. ###############################
  4. # END OF CHANGEABLE OPTIONS   #
  5. ###############################
  6.  
  7. # START MAIN PROGRAM 
  8. # ------------------
  9.  
  10. &ReadParse;
  11. $Session = $in{'SessionID'};
  12. if    ($Session eq '')               {&GetSession;}  # Get a session id
  13. elsif ($Session eq '*SeSiOnId*')     {&GetSession;};  # Get a session id
  14.  
  15. $targetFile = $ENV{'PATH_TRANSLATED'};
  16. $ItemID = $in{'ItemID'};
  17.  
  18. $Debug=$in{'Debug'};
  19. if ($Debug eq 'True') {
  20.         print "Content-Type: text/html\n\n";
  21.         print "<HTML><HEAD><TITLE>Debug Info</TITLE></HEAD><BODY>";
  22.         print "Session=$Session<br>";
  23.         print "Target =$targetFile<br>";
  24.         print "</BODY></HTML>";
  25. } # debug info 
  26.  
  27. print "Content-Type: text/html\n\n";
  28.         
  29. print (&ReplaceState($targetFile, "SessionID=$Session")); # send the info .. 
  30.  
  31. exit(1);
  32.  
  33. # GENERAL SUBROUTINES
  34. # -------------------
  35.  
  36. sub ReadParse {
  37.   local (*in) = @_ if @_;   local ($i, $loc, $key, $val);
  38.   if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } 
  39.   elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); }
  40.   @in = split(/&/,$in);
  41.   foreach $i (0 .. $#in) {
  42.     $in[$i] =~ s/\+/ /g;
  43.     ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
  44.     $key =~ s/%(..)/pack("c",hex($1))/ge;
  45.     $val =~ s/%(..)/pack("c",hex($1))/ge;
  46.     $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
  47.     $in{$key} .= $val;
  48.   }
  49.   return 1; # just for fun
  50. } # ReadParse
  51.  
  52. sub GetSession {
  53.         $Session = $$; # use the current PID as the new session id,
  54.         # we might change this later to a cyclic queue to ensure that
  55.         # a speicified # of customers can access the site at once.
  56.         &StartSession($Session); # StartSession is generated by CatMake
  57. } # GetSession 
  58.  
  59. sub ReplaceState {
  60.         local($fileName, $state) = @_;
  61.  
  62.         open(INPUT, "<$fileName") || "Error opening URL.\n";
  63.  
  64.         undef $/; # Read in the entire file 
  65.         ($data = <INPUT>) || "Error reading file.\n";
  66.  
  67.         $data =~ s/\*SeSiOnId\*/$Session/g;
  68.  
  69. #        while ($data =~ /SessionID=\*SeSiOnId\*/) { 
  70. #        } # find the replaceables .. 
  71.  
  72.         if (!dbmopen(%subs, "items", 0777)) {
  73.                 "Can not read items database";
  74.                 exit 1;
  75.         }
  76.  
  77.         if (!dbmopen(%items, "$Session", 0777)) {
  78.                 "Error opening the session data";
  79.                 exit 1;
  80.         }
  81.  
  82.         $subItems = $subs{$ItemID};
  83.         if ($subItems != "") {
  84.                 for ( $si = 1; $si <= $subItems; $si++ ) {
  85.                         $TheSubItem = $ItemID . $si;
  86.                         $TheValue = $items{$TheSubItem};
  87.                         $data =~ s/\*$TheSubItem\*/$TheValue/g;
  88.                 } # for 
  89.         } # there are sub items 
  90.  
  91.         dbmclose(%items);
  92.         dbmclose(%subs);
  93.  
  94.         $data; # return the file 
  95.  
  96. } # ReplaceSession
  97.  
  98.  
  99. sub PrintError {
  100. print("Content-Type: text/html\n\n");
  101. print <<EOF;
  102. <HTML> 
  103. <HEAD><TITLE>ERROR</TITLE></HEAD>
  104. <BODY>
  105. <H1 ALIGN=CENTER>$TITLE</H1>  <HR>
  106. An error occured in the script!
  107. <HR>
  108. EOF
  109. } # PrintError
  110.  
  111. sub PrintSuccess {
  112. print <<EOF;
  113. <HTML> 
  114. <HEAD><TITLE>Success</TITLE></HEAD>
  115. <BODY>
  116. <H1 ALIGN=CENTER>$TITLE</H1>  <HR>
  117. Your request was processed succesfuly!
  118. Thank you for using a catalog maker product!
  119. <HR>
  120. EOF
  121. } # PrintSuccess
  122.  
  123.